package com.ruoyi.ly.controller;

import com.ruoyi.ly.domain.dto.MobileBannerAddDTO;
import com.ruoyi.ly.domain.dto.MobileBannerUpdateDTO;
import com.ruoyi.ly.domain.dto.PageMobileBannerDTO;
import com.ruoyi.ly.domain.vo.MobileBannerVO;
import com.ruoyi.ly.service.MobileBannerService;
import com.ruoyi.ly.utils.PageResult;
import com.ruoyi.ly.utils.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/mobile/banner")
@Api("轮播图接口")
@Slf4j
public class MobileBannerController {

    @Autowired
    private MobileBannerService mobileBannerService;


    //  新增轮播图信息
    @PostMapping("/add")
    @ApiOperation(value = "新增轮播图信息")
    public Result<String> insert(@RequestBody MobileBannerAddDTO mobileBannerDTO){
        log.info("新增轮播图信息");
        mobileBannerService.save(mobileBannerDTO);
        return Result.success();
    }

    //分页查询
    @GetMapping("/page")
    @ApiOperation(value = "分页查询")
    public Result<PageResult> page(PageMobileBannerDTO pageMobileBannerDTO) {
        log.info("分页查询：{}", pageMobileBannerDTO);
        PageResult pageResult = mobileBannerService.pageQuery(pageMobileBannerDTO);
        return Result.success(pageResult);
    }

    //删除轮播图
    @DeleteMapping("/delete/{id}")
    @ApiOperation(value = "删除轮播图")
    public Result delete(@PathVariable("id")Long id) {
        log.info("删除轮播图：{}", id);
        mobileBannerService.delete(id);
        return Result.success();
    }

    //修改轮播图
    @PutMapping("/update")
    @ApiOperation(value = "修改轮播图")
    public Result update(@RequestBody MobileBannerUpdateDTO mobileBannerUpdateDto) {
        log.info("修改轮播图：{}", mobileBannerUpdateDto);
        mobileBannerService.update(mobileBannerUpdateDto);
        return Result.success();
    }

    //根据轮播图id查询轮播图详情
    @GetMapping("/{id}")
    @ApiOperation(value = "根据轮播图id查询轮播图详情")
    public  Result<MobileBannerVO> selectById(@PathVariable Long id) {
        log.info("根据轮播图id查询轮播图详情：{}",id);
        MobileBannerVO mobileBannerVO = mobileBannerService.selectById(id);
        return Result.success(mobileBannerVO);
    }
}
